package com.example.a14110100420.yuejian.Fragment.club;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.example.a14110100420.yuejian.R;
import com.example.a14110100420.yuejian.WSerivice.ClubService;
import com.example.a14110100420.yuejian.Wbase.Conast;
import com.example.a14110100420.yuejian.Wbean.club.ClubDetail;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * A simple {@link Fragment} subclass.
 */
public class Club_Intro_Fragment extends Fragment {

    //传值给详情页，避免重复造轮子
    public String club_name;
    public String club_fans;
    public String club_pic;


    private TextView club_intro;
    private TextView club_adress;
    private TextView club_tel;
    private TextView club_time;
    private TextView club_suggest;

    private View view;


    public Club_Intro_Fragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.activity_club__video_, container, false);
        event();
        init();
        return view;
    }
    private void event(){
        club_adress = view.findViewById(R.id.club_adress);
        club_intro = view.findViewById(R.id.club_detail);
        club_tel = view.findViewById(R.id.club_tel);
        club_time = view.findViewById(R.id.club_time);
        club_suggest = view.findViewById(R.id.club_suggest);
    }
    private void init(){
        Intent intent = getActivity().getIntent();
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(Conast.base_Url)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        ClubService service = retrofit.create(ClubService.class);
        Call<ClubDetail> call = service.getClubDetail(intent.getStringExtra("clubid"));
        call.enqueue(new Callback<ClubDetail>() {
            @Override
            public void onResponse(Call<ClubDetail> call, Response<ClubDetail> response) {
                ClubDetail clubDetail = response.body();
                if (clubDetail != null)
                {
                    club_intro.setText(clubDetail.getIntroduction());
                    club_adress.setText(clubDetail.getClub_contact());
                    club_time.setText(clubDetail.getOpen_time());
                    club_tel.setText(clubDetail.getClub_tel());
                    club_suggest.setText(clubDetail.getEquipsuggest());


                }

            }

            @Override
            public void onFailure(Call<ClubDetail> call, Throwable t) {
                Toast.makeText(getActivity(),"请求失败",Toast.LENGTH_SHORT).show();

            }
        });
    }
}
